#ifndef __GEFFECT_H__
#define __GEFFECT_H__

#include "Sprites.h"
#include "d3d9.h"
#include "d3dx9.h"
#include "Particle.h"

#define ITEMS_F_W		35
#define ITEMS_F_H		70

#define EFFECT_IMAGE "Images\\Effect.png"
#define PARTICLE_IMAGE "Images\\Particle.png"


struct InfoEffect{

	int x;
	int y;
	int index;
	int deltaYSprite;
	int spriteCount;
	int timeDelay;
	int lastTime;

};

class CEffect
{
public:
	LPDIRECT3DTEXTURE9	_image;	
	LPDIRECT3DTEXTURE9	_imageParticle;	
	vector<InfoEffect*>  listInfo;
	CParticleEngine *par;
	CEffect()
	{
		//create particle
		_imageParticle=CSprites::LoadTexture(PARTICLE_IMAGE,0);	
		Vector2D pos;
		pos.x = 250; pos.y = 250;
		par = new CParticleEngine(CSprites::_spriteHandler, pos);
		par->Init(_imageParticle);

		_image=CSprites::LoadTexture(EFFECT_IMAGE,0);	
	}
	void Add(int x,int y,int kind)
	{
		if(kind==0)//particle
			par->GenarateNewParticle(x, y, 10+rand()%10);	
		InfoEffect* info=new InfoEffect;
 		info->x=x;
		info->y=y;
		info->index=0;//effect for coin
		info->lastTime=GetTickCount();
		if(kind==1)
		{
			info->deltaYSprite=25;
			info->spriteCount=6;
			info->timeDelay=100;
			
		}
		listInfo.push_back(info);

	}
	void Draw(int VirtualLeft)
	{
		par->Render(VirtualLeft);
		par->Update(15);
		RECT rec;
		for(int i=0;i<listInfo.size();i++)
		{
			InfoEffect* info=listInfo[i];
			
			if(GetTickCount()-info->lastTime>info->timeDelay)
			{
				info->lastTime=GetTickCount();
				info->index++;
			}
			if(info->index>info->spriteCount)
			{
				listInfo.erase(listInfo.begin()+i);
				continue;
			}

			rec.left=info->index*ITEMS_F_W;
			rec.top=info->deltaYSprite;
			rec.bottom=rec.top+ITEMS_F_H;
			rec.right=rec.left+ITEMS_F_W;
			CSprites::_spriteHandler->Begin(D3DXSPRITE_ALPHABLEND);
			D3DXVECTOR3	position((float)(info->x-VirtualLeft),(float)info->y,0);
			CSprites::_spriteHandler->Draw(	_image,
				&rec,
				NULL,
				&position,
				D3DCOLOR_XRGB(255,255,255));
			CSprites::_spriteHandler->End();
		}

	}
};
#endif